package jp.co.piratealliance.pirateAllianceWeb.web.action.goods;

import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

import jp.co.piratealliance.pirateAllianceWeb.common.base.BaseAction;
import jp.co.piratealliance.pirateAllianceWeb.dto.goods.GoodsInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.service.goods.GoodsService;

/**
 * copyright pirate alliance team 2014
 *
 * @author songyong
 */

public class GetGoodsListWebAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private GoodsService goodsService;
	private List<GoodsInfoDto> goodsList;
	private GoodsInfoDto goodsInfoDto;
	public GoodsService getGoodsService() {
		return goodsService;
	}
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	public List<GoodsInfoDto> getGoodsList() {
		return goodsList;
	}
	public void setGoodsList(List<GoodsInfoDto> goodsList) {
		this.goodsList = goodsList;
	}
	public GoodsInfoDto getGoodsInfoDto() {
		return goodsInfoDto;
	}
	public void setGoodsInfoDto(GoodsInfoDto goodsInfoDto) {
		this.goodsInfoDto = goodsInfoDto;
	}
	public String homePageGoodsList(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		if(session.get("oldURL")!=null){
			session.remove("oldURL");
			}
		this.goodsList=this.goodsService.selectHomePageGoods();
		  return SUCCESS;
	}
	public String logOut(){
	    ActionContext.getContext().getSession().remove("user");
		return	homePageGoodsList();
	}
	public String searchGoodById(){
		String goodsId = ServletActionContext.getRequest().getParameter("goodsId");
		String languageId = ServletActionContext.getRequest().getParameter("languageId");
		//this.goodsList= this.goodsService.getGoodsListByGoodsId(goodsId);
		this.goodsList=this.goodsService.getGoodsListByGoodsIdLanguageId(goodsId, languageId);
		this.goodsInfoDto=this.goodsList.get(0);
		return SUCCESS;
	}

}
